@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<section class="panel panel-padding">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

        <form class="layui-form" action="">

            <fieldset class="layui-elem-field">
                <legend>小程序打开弹出广告</legend>
                <div class="layui-field-box">

                    <div class="layui-form-item">
                        <label class="layui-form-label">上传excel</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="HomeAdImage" />
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="btn_HomeAdImage">上传图片</button>
                                <div class="layui-upload-list">
                                    @if (string.IsNullOrWhiteSpace(@Model?.HomeAdImage))
                                    {
                                        <img class="layui-upload-img" id="upload_HomeAdImage" style="height: auto; width: 500px;">
                                    }
                                    else
                                    {
                                        <img class="layui-upload-img" id="upload_HomeAdImage" style="height: auto; width: 300px;" src="@(ViewBag.Domain)@(@Model.HomeAdImage)">
                                    }

                                    <p id="test-upload-demoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-btn submitbtn" lay-submit lay-filter="submit">提交数据</div>
                    @*<button id="closewindow" class="layui-btn layui-btn-danger">关闭窗口</button>*@
                    <div class="layui-btn layui-btn-danger closewindow">关闭窗口</div>
                    <div class="layui-btn layui-btn-danger refreshwindow">重新加载</div>
                </div>
            </div>
        </form>
    </div>
</section>

@section Scripts{
<script>

    var editorElement = null;

    layui.define(['element', 'upload', 'jquery', 'form', 'table', 'laydate'], function () {
        var $ = layui.jquery
            , upload = layui.upload,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            element = layui.element;

        //Info 初始化
        abc.infoInit();
        //提交
        form.on('submit(submit)', function (obj) {
            obj.field.HomeAdIsEnable = $("#HomeAdIsEnable").is(":checked");
            $.post("@(Url.Action("AdSetting"))", obj.field, function (result) {
                if (result.State) {
                    //var index = parent.layer.getFrameIndex(window.name);
                    //parent.layer.close(index);//关闭当前页
                }
                layer.msg(result.Msg);
            });

            return false;
        });
        ////关闭当前页面
        //$("#closewindow").on("click",function(){
        //    //当你在iframe页面关闭自身时
        //    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        //    parent.layer.close(index); //再执行关闭
        //});

        @*abc.InitUpLoadImage(upload, '@(Url.Action("ImgUpload"))?type=Ad', 'btn_HomeAdImage', 'HomeAdImage', 'upload_HomeAdImage');
        abc.InitUpLoadImage(upload, '@(Url.Action("ImgUpload"))?type=Ad', 'btn_AdImage', 'AdImage', 'upload_AdImage');*@
        abc.initFileUpLoad({
            elem: "btn_HomeAdImage",auto:true, url: '@(Url.Action("UploadFile"))?type=Excel'
            , done: function (res, index, upload) {
                $('#HomeAdImage').val(res.Data.src);
                $('#upload_HomeAdImage').attr('src', res.Data.httpsrc);
                console.log(res);

            }
            , error: function (index, upload) {
            }
        });

    });
</script>
}
